package com.liner.collection;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 集合之间的操作
 */
public class CollectionOperDemo {
    public static void main(String[] args) {
        Collection<Object> c1 = new ArrayList<>();
        Collection<Object> c2 = new ArrayList<>();
        Collection<Object> c3 = new ArrayList<>();
        c1.add("java");
        c1.add("ios");
        c1.add("C++");
        c2.add("one");
        c2.add("two");
        c3.add("one");
        c3.add("two");
        c3.add("three");

        c1.addAll(c2);  //将 c2 添加到 c1 末尾
        System.out.println("c1:" + c1);
        System.out.println("c2:" + c2);

        System.out.println("c3:" + c3);

        System.out.println("c2中是否包含c3:" + c2.containsAll(c3)); //
        System.out.println("c3中是否包含c2:" + c3.containsAll(c2)); //

        c1.retainAll(c2);   //取交集 c1中仅保留与c2所共有的元素，而c2不变
        System.out.println("c1:" + c1);
        System.out.println("c2:" + c2);
        System.out.println("c3:" + c3);
        c1.removeAll(c3);   //删交集 将c1中与c3共有的元素删除，c3不变
        System.out.println("c1:" + c1);
        System.out.println("c2:" + c2);
        System.out.println("c3:" + c3);

    }

}
